package com.xpec.c4.db;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xpec.c4.db.cfg.DBConfig;

/**
 * 数据库线程类<br>
 * 定时扫描全部用户数据，并把符合要求的用户数据提交给数据库保存
 * 
 * @author Bany
 * 
 */
public class DBUserThread extends Thread {
	
	private static Log log = LogFactory.getLog(DBUserThread.class);
	
	/**
	 * 单例对象
	 */
	private static DBUserThread dbThread = new DBUserThread();

	private DBUserThread() {

	}

	/**
	 * 获得数据库线程的单例
	 * 
	 * @return 数据库线程对象
	 */
	public static synchronized DBUserThread getInstance() {
		if (dbThread == null) {
			dbThread = new DBUserThread();
		}
		return dbThread;

	}

	/**
	 * 停止线程的参数
	 */
	private boolean stop = false;

	@Override
	public void run() {
		while (!stop) {
			log.info("======= DB Thread begin===========");
			// DBAction.saveAllUserByIntervalTime();
			// DBAction.clearTimeoutPO();
			log.info("======= DB Thread end=============");
			try {
				sleep(DBConfig.getScanIntervalTime());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}
	}

	/**
	 * 线程停止
	 */
	public void threadStop() {
		stop = true;
	}

}
